package cn.itsource.dd.controller;

import cn.itsource.basic.query.Basequery;
import cn.itsource.basic.util.AxajResult;
import cn.itsource.basic.util.PageInfo;
import cn.itsource.dd.domain.Type;
import cn.itsource.dd.service.ITypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/type")
public class TypeController {
    @Autowired
    private ITypeService typeService;


        //查询数据字典类型分页列表展示
          @PatchMapping
        public PageInfo<Type> findAll(@RequestBody Basequery basequery){
              return typeService.findAllByQuery(basequery);
        }
    /**
     * 删除数据字典类型通过id
     */
    @DeleteMapping("/{id}")
    public AxajResult delete(@PathVariable("id")Long id) {
        try {
            typeService.delete(id);
            return new AxajResult();
        } catch (Exception e) {
            return new AxajResult(false,e.getMessage());
        }
    }
    /**
     * 通过id识别是添加还是修改
     */
    @PostMapping
    @ApiOperation(value = "部门添加或修改",notes = "如果有id就是修改否则就是添加")
    public AxajResult save(@RequestBody Type type) {
        try {
            typeService.save(type);
            return new AxajResult();
        } catch (Exception e) {
            return new AxajResult(false,e.getMessage());
        }
    }
}
